package com.hsylient.javase.chapter11.practice;

import java.util.Objects;

/**
 * 模拟龟兔赛跑
 */
public class GuiTu implements Runnable {

    private static String winnerName;

    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName() + "跑了" + i + "步");
        }
        winnerName = Thread.currentThread().getName();
    }

    public static void main(String[] args) throws InterruptedException {
        GuiTu guiTu = new GuiTu();
        new Thread(guiTu, "乌龟").start();
        new Thread(guiTu, "兔子").start();
        Thread.sleep(1000);
        if (!Objects.isNull(winnerName)) {
            System.out.println("胜利者是:" + winnerName);
        }
    }
}
